<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    (function(){
        function Tank(){
            this.dom = null
            this.speed = 0
            this.color = ''
            this.run = function(){}
        }
        var instance = null
        function getInstance(){
            // if(instance){
            //     return instance
            // }else{
            //     return instance = new Tank
            // }
        //简写方式
        return instance || (instance = new Tank)

        }
        window.SingleTon = {getInstance}
        // 给window对象添加一个属性(将SingleTon彻底暴露在外部)
        // window对象身上的所有属性，在使用的时候，都可以省略window
    })()
    let x = SingleTon.getInstance()
    let y = SingleTon.getInstance()
    let z = SingleTon.getInstance()
    console.log(x,y,z);
    console.log(x==y);
    console.log(x==z);
    console.log(z==y);
</script>